<?php

class Portal_model extends CI_Model {

	function Portal_model() {
		// Call the Model constructor
		parent::__construct();
	}

		//Get Featured Banner - Home page
		//Feature
	function getHomeFeaturedImage($lang) {
		if($lang == "english") {
			$lang = 1;
		}
		$tsql_callSP = '{call sp_getHomeFeaturedImage(?)}';

		$params = array(
		array($lang, SQLSRV_PARAM_IN)
		);

		$results = $this->db->exec_query($tsql_callSP, $params);

		$data = array();

		if($results) {
			while ($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) {
				$data[] = $row;
			}
		}

		return $data;
	}
	
	function getVideo($page = 'Home', $market = 'ID') {
		$str = "select TOP 1 b.*, bg.Name, pb.SortOrder
				from dbo.Pages p
				left join dbo.PageBanner pb ON p.Page_ID = pb.PageFID
				left join dbo.Banner b ON b.Banner_ID = pb.BannerFID
				left join dbo.BannerGroup bg ON bg.BannerGroup_ID = b.BannerGroupFID
				WHERE p.SystemName = '". $this->db->escape_str($page) ."' and p.MarketFID = '". $this->db->escape_str($market) ."' AND b.LanguageFID = 1";
		
		$query = $this->db->query($str);
		
		if($query->num_rows() > 0) {
			return $query->row();	
		} else {
			return false;
		}
	}
	
	function getHomePageContent($page = 'Home', $market = 'ID', $language = 1) {
		$str  = "SELECT c.Content,c.Type,c.Description,p.SystemName
				FROM Pages p
				JOIN HomePageContent c ON c.Page_ID = p.Page_ID
				where p.SystemName = '". $this->db->escape_str($page) ."' and p.MarketFID = '". $this->db->escape_str($market) ."' and c.LanguageFID = ". $this->db->escape($language) ."";
		
		$query = $this->db->query($str);
		if($query->num_rows() > 0) {
			return $query->result();	
		} else {
			return false;
		}
	}

}

?>
